package com.aaa.hospital.controller;

import com.aaa.hospital.aop.Log;
import com.aaa.hospital.pojo.query.NewsQuery;
import com.aaa.hospital.pojo.vo.NewsVO;
import com.aaa.hospital.result.AjaxResult;
import com.aaa.hospital.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program:qy888
 * @description:www
 * @author:LJW
 * @version: 1.0
 * @create:2022-2-15 20:47
 */

@RestController
@RequestMapping("news")
public class NewsController {

    @Autowired
    private NewsService newsService;

    @RequestMapping("show/{id}")
    public AjaxResult show(@PathVariable("id") Integer id){
        System.out.println(id);
        return newsService.show(id);
    }

    @RequestMapping("query")
    public AjaxResult query(NewsQuery query){
        return newsService.queryNews(query);
    }

    @RequestMapping("addNews")
    @Log("添加新闻")
    public AjaxResult addNews(NewsVO newsVO){
        String[] str3 = {"草","操","滚"};
        String[] str = {"SB","Sb","sB","sb","傻比",};
        String[] str1 = {"大法好","大傻杯","他妈的","TMD"};

        for (String s : str3) {
            String result = newsVO.getTitle().replace(s,"*");
            String result1 = newsVO.getContent().replace(s,"*");
            newsVO.setTitle(result);
            newsVO.setContent(result1);
        }
        for (String s : str) {
            String result = newsVO.getTitle().replace(s,"**");
            String result1 = newsVO.getContent().replace(s,"**");
            newsVO.setTitle(result);
            newsVO.setContent(result1);
        }
        for (String s : str1) {
            String result = newsVO.getTitle().replace(s,"***");
            String result1 = newsVO.getContent().replace(s,"***");
            newsVO.setTitle(result);
            newsVO.setContent(result1);
        }

        return newsService.addNews(newsVO);
    }

    @RequestMapping("deletenews/{id}")
    @Log("删除新闻")
    public AjaxResult deletenews(@PathVariable("id") Integer id){
        System.out.println(id);
        return newsService.deletenews(id);
    }

    @RequestMapping("get/{id}")
    public AjaxResult get(@PathVariable("id") Integer id){
        System.out.println(id);
        return newsService.get(id);
    }

    @RequestMapping("index")
    public AjaxResult index(){
        return newsService.index();
    }
}
